package org.sean.framework.util;

import org.sean.framework.logging.Logger;

/**
 * 枚举工具类
 */
public class EnumUtil {
    private static final Logger LOG = Logger.newInstance(EnumUtil.class);

    private EnumUtil() {
    }

    /**
     * 字符串转换Enum
     *
     * @param <T>      T
     * @param enumType 枚举类型
     * @param string   枚举名
     * @return 枚举
     */
    public static <T extends Enum<T>> T getEnumFromString(Class<T> enumType, String string) {
        if (enumType != null && !StringUtil.isEmpty(string)) {
            try {
                return Enum.valueOf(enumType, string.trim());
            } catch (Exception e) {
                LOG.printStackTrace(e);
            }
        }
        return null;
    }

}
